//
//  MyWIFITableViewCell.m
//  Router
//
//  Created by teki on 15/10/19.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "MyWIFITableViewCell.h"
#import "BindDeviceModel.h"
#import "WIFIModel.h"

#define icon_unSelectedImage     ([UIImage imageNamed:@"my_wifi"])
#define icon_selectedImage ([UIImage imageNamed:@"my_wifi_on"])


#define select_unSelectedImage ([UIImage imageNamed:@"my_selected_non"])
#define select_selectedImage ([UIImage imageNamed:@"my_selected"])



@interface MyWIFITableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@property (weak, nonatomic) IBOutlet UILabel *wifiNameLabel;

@property (weak, nonatomic) IBOutlet UIImageView *selectedImageView;
@end

@implementation MyWIFITableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        // 初始化时加载Cell.xib文件
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
        
        // 如果路径不存在，return nil
        if (arrayOfViews.count < 1)
        {
            return nil;
        }
        // 如果xib中view不属于UITableViewCell类，return nil
        if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UITableViewCell class]])
        {
            return nil;
        }
        // 加载nib
        self = [arrayOfViews objectAtIndex:0];
    }
    return self;
}


- (void)awakeFromNib {

    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}




- (void)setDeviceModel:(BindDeviceModel *)deviceModel
{
    _deviceModel = deviceModel;
    WIFIModel *wifi = [UserSingleton shareInstance].userModel.wifi;
    if ([wifi.device_id isEqualToString:deviceModel.deviceID])
    {
        self.iconImageView.image = icon_selectedImage;
        self.selectedImageView.image = select_selectedImage;
        self.wifiNameLabel.text = deviceModel.ssid;
        self.wifiNameLabel.textColor = NavgationBarBackgroundColor;
    }
    else
    {
        self.iconImageView.image = icon_unSelectedImage;
        self.selectedImageView.image = select_unSelectedImage;
        self.wifiNameLabel.text = deviceModel.ssid;
        self.wifiNameLabel.textColor = SeparatorLineColor;
    }

}
@end
